<template>
  <!-- 首检任务清单 -->

  <p-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <p-form layout="inline" @keyup.enter.native="searchQuery">
        <p-row :gutter="24">
          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <p-form-item label="检验状态">
              <p-select placeholder="请选择检验状态" v-model="queryParam.inspectStatus" allowClear>
                <p-select-option :value="1">待检</p-select-option>
                <p-select-option :value="2">待线长确认</p-select-option>
                <p-select-option :value="3">待IPQC复核</p-select-option>
                <p-select-option :value="4">检验完成</p-select-option>
              </p-select>
            </p-form-item>
          </p-col>
          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <p-form-item label="车间">
              <p-input placeholder="请输入车间" v-model="queryParam.workroomname"></p-input>
            </p-form-item>
          </p-col>
          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <p-form-item label="二级工序">
              <p-input placeholder="请输入二级工序" v-model="queryParam.processTwo"></p-input>
            </p-form-item>
          </p-col>
        </p-row>
        <p-row :gutter="24">
          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <p-form-item label="产品编码">
              <p-input placeholder="请输入产品编码" v-model="queryParam.mcode"></p-input>
            </p-form-item>
          </p-col>

          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <p-button type="primary" @click="searchQuery" icon="search">查询</p-button>
              <p-button
                      type="primary"
                      @click="searchReset"
                      icon="reload"
                      style="margin-left: 8px"
              >重置</p-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <p-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>-->
            </span>
          </p-col>
        </p-row>
      </p-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <p-button @click="handleAdd" type="primary" icon="plus">新增</p-button> -->

      <template
              v-if="cgButtonList != null && cgButtonList.length>0"
              v-for="(item,index) in cgButtonList"
      >
        <p-button
                v-if=" item.optType=='js' && (item.groupTag == null || item.groupTag == '' )"
                :key=" 'cgbtn'+index "
                @click="cgButtonJsHandler(item.buttonCode)"
                type="primary"
                :icon="item.buttonIcon"
        >{{ item.buttonName }}</p-button>
        <p-button
                v-else-if=" item.optType=='action' && (item.groupTag == null || item.groupTag == '' )"
                :key=" 'cgbtn'+index "
                @click="cgButtonActionHandler(item.buttonCode)"
                type="primary"
                :icon="item.buttonIcon"
        >{{ item.buttonName }}</p-button>
      </template>

      <!-- 高级查询区域 -->
      <j-super-query
              :fieldList="fieldList"
              ref="superQueryModal"
              @handleSuperQuery="handleSuperQuery"
      ></j-super-query>

      <p-dropdown v-for="(item,index) in groupTag" :key="index">
        <p-button>
          {{item.name}}
          <p-icon type="down" />
        </p-button>
        <p-menu slot="overlay">
          <template v-for="(items,indexs) in item.data">
            <p-menu-item
                    v-if=" items.optType=='js' "
                    :key="indexs"
                    @click="cgButtonJsHandler(items.buttonCode)"
            >
              <p-icon :type="items.buttonIcon" />
              {{items.buttonName}}
            </p-menu-item>
            <p-menu-item
                    v-else-if=" items.optType=='action' "
                    :key="indexs"
                    @click="cgButtonActionHandler(items.buttonCode)"
            >
              <p-icon :type="items.buttonIcon" />
              {{items.buttonName}}
            </p-menu-item>
          </template>
        </p-menu>
      </p-dropdown>

      <!-- <p-dropdown v-if="selectedRowKeys.length > 0">
        <p-menu slot="overlay">
          <p-menu-item key="1" @click="batchDel">
            <p-icon type="delete" />删除
          </p-menu-item>
        </p-menu>
        <p-button style="margin-left: 8px">
          批量操作
          <p-icon type="down" />
        </p-button>
      </p-dropdown>-->
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <!-- <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>-->

        <span style="float:right;">
          <a @click="handleExportXls('首检任务')">
            <p-icon type="download" />导出
          </a>
          <p-divider type="vertical" />
          <p-upload
                  name="file"
                  :showUploadList="false"
                  :multiple="false"
                  :headers="tokenHeader"
                  :action="importExcelUrl"
                  @change="handleImportExcel"
          >
            <a>
              <p-icon type="import" />导入
            </a>
          </p-upload>
          <p-divider type="vertical" />
          <a @click="loadData()">
            <p-icon type="sync" />刷新
          </a>
          <p-divider type="vertical" />
          <p-popover title="自定义列" trigger="click" placement="leftBottom" :overlay-style="getWidth">
            <template slot="content">
              <p-checkbox-group
                      @change="onColSettingsChange"
                      v-model="settingColumns"
                      :defaultValue="settingColumns"
              >
                <p-row>
                  <template v-for="(item,index) in defColumns">
                    <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                      <p-col :span="12">
                        <p-checkbox :value="item.dataIndex">{{ item.title }}</p-checkbox>
                      </p-col>
                    </template>
                  </template>
                </p-row>
              </p-checkbox-group>
            </template>
            <a>
              <p-icon type="setting" />自定义列
            </a>
          </p-popover>
        </span>
        <div style="clear: both;"></div>
      </div>

      <!-- 表格 :dataSource即表格的所有数组值 -->
      <p-table
              ref="table"
              size="middle"
              bordered
              rowKey="id"
              :columns="columns"
              :scroll="tableScroll"
              :dataSource="dataSource"
              :pagination="ipagination"
              :loading="loading"
              :customRow="clickThenSelect"
              :rowClassName="setRowClassName"
              @change="handleTableChange"
      >
        <!-- :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type:'radio'}" -->

        <!-- 送检单号插槽 -->
        <!-- isPallet:用来判断跳转普通操作页面还是线材/组件预制页面 -->
        <!-- inspectStatus:用来判断跳转首检操作还是 首检确认操作 首检复核操作-->
        <template slot="inspectBillno" slot-scope="text,record">
          <div v-if="record.inspectStatus==4">{{text}}</div>
          <a  v-else @click="router_url(record.id,record.isPallet,record.inspectStatus)">{{text}}</a>
        </template>

        <!-- 检验状态插槽
        <template slot="inspectStatus" slot-scope="text,record">
          <div
            v-if="record.inspectStatus != 4"
            @click="router_url(record.id,record.isPallet,record.inspectStatus)"
            style="cursor:pointer; color:red;"
          >{{data_text=data_dic(text,'inspectStatus')}}</div>

          <div
            v-else
            @click="router_url(record.id,record.isPallet,record.inspectStatus)"
            style="cursor:pointer; color:green;"
          >{{data_text=data_dic(text,'inspectStatus')}}</div>
        </template>-->


        <template slot="inspectStatus" slot-scope="text,record">
          <p-tag v-if="text==1"  color="blue" ><p-icon type="clock-circle" />待检</p-tag>
          <p-tag v-else-if="text==2" color="orange" ><p-icon type="exclamation-circle" />待线长确认</p-tag>
          <p-tag v-else-if="text==3" color="orange" ><p-icon type="exclamation-circle" />待IPQC复核</p-tag>
          <p-tag v-else-if="text==4" color="green" ><p-icon type="check-circle" />检验完成</p-tag>

        </template>


        <!--
                <template slot="inspectStatus" slot-scope="text,record">
                  &lt;!&ndash; <div  :color="(record.status==3||record.status==4)?'red':'black'">{{ text }}</div>&ndash;&gt;
                  <div v-if="!text" >/</div>
                  <p-tag v-else-if="text==1" color="green"><p-icon type="check-circle" />合格</p-tag>
                  <p-tag v-else-if="text==2" color="red"><p-icon type="close-circle" />不合格</p-tag>
                </template>

        -->





        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>

        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <img
                  v-else
                  :src="getImgView(text)"
                  height="25px"
                  alt="图片不存在"
                  style="max-width:80px;font-size: 12px;font-style: italic;"
          />
        </template>

        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
          <p-button
                  v-else
                  :ghost="true"
                  type="primary"
                  icon="download"
                  size="small"
                  @click="uploadFile(text)"
          >下载</p-button>
        </template>

        <!-- <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <p-divider type="vertical" />
          <p-dropdown>
            <a class="ant-dropdown-link">
              更多
              <p-icon type="down" />
            </a>
            <p-menu slot="overlay">
              <p-menu-item>
                <p-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </p-popconfirm>
              </p-menu-item>
              <template v-if="cgButtonLinkList && cgButtonLinkList.length">
                0
                v-for="(btnItem,btnIndex) in cgButtonLinkList"
                >
                <p-menu-item :key="'cgbtnLink'+btnIndex" v-if="showLinkButton(btnItem,record)">
                  <a
                    href="javascript:void(0);"
                    @click="cgButtonLinkHandler(record,btnItem.buttonCode,btnItem.optType)"
                  >
                    <p-icon v-if="btnItem.buttonIcon" :type="btnItem.buttonIcon" />
                    {{ btnItem.buttonName }}
                  </a>
                </p-menu-item>
              </template>
            </p-menu>
          </p-dropdown>
        </span>-->




      </p-table>
    </div>


    <p-drawer
            title="详情信息"
            placement="right"
            :width="980"
            :closable="false"
            :visible="drawerVisible"
            @close="drawerClose"
    >
      <p-divider orientation="left">
        主信息
      </p-divider>

      <p-descriptions bordered  size="small">
        <p-descriptions-item label="送检单号">
          {{baseInfoData.inspectBillno}}
        </p-descriptions-item>
        <p-descriptions-item label="生产工单">
          {{baseInfoData.productionBillno}}
        </p-descriptions-item>
        <p-descriptions-item label="工序工单">
          {{baseInfoData.processBillno}}
        </p-descriptions-item>
        <p-descriptions-item label="产品编号">
          {{baseInfoData.mcode}}
        </p-descriptions-item>
        <p-descriptions-item label="产品名称">
          {{baseInfoData.mname}}
        </p-descriptions-item>
        <p-descriptions-item label="二级工序">
          {{baseInfoData.processTwo}}
        </p-descriptions-item>
        <p-descriptions-item label="线体">
          {{baseInfoData.linename}}
        </p-descriptions-item>
        <p-descriptions-item label="设备编码">
          {{baseInfoData.deviceCode}}
        </p-descriptions-item>
        <p-descriptions-item label="检验次数">
          {{baseInfoData.inspectTimes}}
        </p-descriptions-item>
        <p-descriptions-item label="检验人">
          {{baseInfoData.inspectBy}}
        </p-descriptions-item>
        <p-descriptions-item label="送检时间">
          {{baseInfoData.sendInspectTime}}
        </p-descriptions-item>
      </p-descriptions>


      <p-divider orientation="left">
        其他信息
      </p-divider>

      <p-collapse v-model="activeKey">
        <p-collapse-panel key="1" header="检验项目">
          <p-row v-if="pageState==3||pageState==4">
            <p-select
                    showSearch
                    v-model="currentLine"
                    @change="currentLineChange"
                    style="width: 200px"
            >
              <p-select-option
                      v-for="(item,index) in selectLineList"
                      :key="index"
                      :value="item"
              >{{item}}</p-select-option>
            </p-select>
          </p-row>
          <p-table
                  v-if="pageState==1||pageState==2"
                  ref="table"
                  size="middle"
                  bordered
                  rowKey="id"
                  :scroll="tableScroll3"
                  :columns="dCPcolumns"
                  :dataSource="baseInfoData.mesQcInspectTaskChildList"
                  :loading="loading"

          >
          </p-table>


          <p-table v-if="pageState==3||pageState==4" :data-source="checkProjectData2" :columns="checkProjectColumns2"   bordered>

          </p-table>
        </p-collapse-panel>

        <p-collapse-panel key="2" header="流程记录">
          <p-table  :data-source="baseInfoData.mesQcApproveRecordList" :columns="approveRecordColumns"  bordered>

          </p-table>
        </p-collapse-panel>
      </p-collapse>

    </p-drawer>
    <!-- <p-tabs defaultActiveKey="1">
      <p-tab-pane tab="任务检验项目" key="1" >
        <mes-qc-inspect-task-child-list :mainId="newSelectedMainId" />
      </p-tab-pane>
    </p-tabs>-->

    <mesQcInspectTask-modal ref="modalForm" :EnhanceJS="EnhanceJS" @ok="modalFormOk"></mesQcInspectTask-modal>
    <!-- 弹出窗 -->
    <Fx-compontens-modal
            @ok="modalFormOk"
            ref="modalCompon"
            :getList="queryInfo"
            :title="title"
            :dictOptions="dictOptions"
    ></Fx-compontens-modal>
  </p-card>
</template>

<script>
  import { axios } from "@/utils/request";
  import { postAction, getAction, deleteAction, api } from "@/api/manage";
  import { JeecgListMixin } from "@/mixins/JeecgListMixin";
  import JSuperQuery from "@/components/jeecg/JSuperQuery.vue";
  import { filterObj } from "@/utils/util";
  import MesQcInspectTaskModal from "./modules/MesQcInspectTaskModal";
  import Vue from "vue";
  import MesQcInspectTaskChildList from "./MesQcInspectTaskChildList";
  /*导入数字字典*/
  import {
    initDictOptions,
    filterMultiDictText,
  } from "@/components/dict/JDictSelectUtil";
  import ButtonExpHandler from "@/components/jeecgbiz/modules/ButtonExpHandler";

  import FxCompontensModal from "@/components/jeecgbiz/FxCompontensModal";

  //高级查询modal需要参数
  const superQueryFieldList = [
    {
      value: "inspectBillno",
      text: "送检单号",
      type: "string",
    },
    {
      value: "workroomname",
      text: "车间",
      type: "string",
    },
    {
      value: "processTwo",
      text: "二级工序",
      type: "string",
    },
    {
      value: "linename",
      text: "线体",
      type: "string",
    },
    {
      value: "productionBillno",
      text: "生产工单",
      type: "string",
    },
    {
      value: "processBillno",
      text: "工序工单",
      type: "string",
    },
    {
      value: "deviceCode",
      text: "设备编码",
      type: "string",
    },
    {
      value: "mcode",
      text: "产品编码",
      type: "string",
    },
    {
      value: "mname",
      text: "产品名称",
      type: "string",
    },

    {
      value: "sendInspectTime",
      text: "送检时间",
      type: "Date",
    },
    {
      value: "updateTime",
      text: "IPQC复核时间",
      type: "Date",
    },
    {
      value: "remainingTime",
      text: "检验剩余时长",
      type: "string",
    },
    {
      value: "inspectTimes",
      text: "检验次数",
      type: "int",
    },
    {
      value: "inspectStatus",
      text: "检验状态",
      type: "select",
      dictCode: "mes_inspect_status", //数据字典对应的key值
    },
    {
      value: "inspectResult",
      text: "检验结果",
      type: "select",
      dictCode: "mes_is_qualified", //数据字典对应的key值
    },
    {
      value: "inspectConclusion",
      text: "检验结论",
      type: "string",
    },
    {
      value: "confirmTime",
      text: "确认时间",
      type: "string",
    },
    {
      value: "confirmBy",
      text: "确认人员",
      type: "select",
      dictCode: "",
    },
    {
      value: "isSimple",
      text: "是否抽检",
      type: "select",
      dictCode: "ba_yn",
    },
    {
      value: "sn",
      text: "SN",
      type: "string",
    },
    {
      value: "inspectFailWs",
      text: "检验不合格工站",
      type: "int",
    },
    {
      value: "currentHandler",
      text: "当前处理人",
      type: "select",
      dictCode: "",
    },
    {
      value: "reworkHandler",
      text: "复核处理人",
      type: "select",
      dictCode: "",
    },
    {
      value: "palletno",
      text: "线号/组件编号",
      type: "string",
    },
  ];

  export default {
    name: "MesQcInspectTaskList",
    mixins: [JeecgListMixin],
    components: {
      JSuperQuery,
      MesQcInspectTaskChildList,
      FxCompontensModal,
      MesQcInspectTaskModal,
    },
    props:['mqVisible','mqLoad','mqData'],
    data() {
      return {
        order_state: "", //订单状态 区分单号是否需要跳转功能
        dataSource: [],
        fieldList: superQueryFieldList,
        superQueryFlag: false,
        superQueryParams: "",
        description: "首检任务管理页面",
        EnhanceJS: "",
        cgButtonLinkList: [],
        cgButtonList: [],
        title: "", //存表名
        groupTag: [],
        queryInfo: [],

        rowId:0,

        methodList:[],
        methodMap:[],
        standardUnitList:[],
        standardUnitMap:[],

        baseInfoData:{},
        drawerVisible:false,
        activeKey:['1'],
        checkProjectData2:[],

        pageState:1,
        currentLine:'',
        selectLineList:[],

        checkProjectColumns2:[
          {
            title: "序号",
            dataIndex: "",
            key: "rowIndex",
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            },
          },
          {
            title: "工站",
            dataIndex: "workStation",
          },
          {
            title: "检验项目",
            dataIndex: "inspectProject",
          },
          {
            title: "检验标准",
            dataIndex: "inspectStandard",
          },
          {
            title: "值类型",
            dataIndex: "valueType",
            customRender: (text) => {
              if (!text) {
                return "";
              } else {
                return  text=="1"?"计量型":"计数型";
              }
            },
          },
          {
            title: "检验手段",
            dataIndex: "inspectMethod",
            customRender:(text)=>{
              if(!text){
                return "";
              }else{
                if(this.methodMap[text]){
                  return this.methodMap[text].title;
                }
                return  "";
              }
            }
          },
          {
            title: "标准值",
            dataIndex: "standardValue",
          },
          {
            title: "上限值",
            dataIndex: "upperValue",
          },
          {
            title: "下限值",
            dataIndex: "downValue",
          },
          {
            title: "参数",
            dataIndex: "paramValue",
          },
          {
            title: "实测值",
            dataIndex: "measuredValue",
          },
          {
            title: "单项判定",
            dataIndex: "individualJudgment",
            customRender: (text) => {
              if (!text) {
                return "NG";
              } else {
                return  text==1?"Pass":"NG";
              }
            },
          },
          {
            title: "检验人",
            dataIndex: "judge",
          },
        ],
        approveRecordColumns:[
          {
            title: "序号",
            dataIndex: "",
            key: "rowIndex",
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            },
          },
          {
            title: "时间",
            dataIndex: "createTime",
            customRender: (text) => {
              return this.formatDate(text+'',"YYYY-MM-DD HH:mm:ss");
            },
          },
          {
            title: "操作人员",
            dataIndex: "opeBy",
          },
          {
            title: "操作内容",
            dataIndex: "remark",
          },
          {
            title: "状态",
            dataIndex: "opeContent",
          },
        ],
        dCPcolumns:[
          {
            title: "序号",
            dataIndex: "",
            key: "rowIndex",
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            },
          },
          {
            title: "工站",
            align: "center",
            dataIndex: "workStation",
          },
          {
            title: "检验项目",
            align: "center",
            dataIndex: "inspectProject",
          },
          {
            title: "检验标准",
            align: "center",
            dataIndex: "inspectStandard",
          },
          {
            title: "值类型",
            align: "center",
            dataIndex: "valueType",
            customRender: (text) => {
              if (!text) {
                return "";
              } else {
                return  text==1?'计量型':'计数型';
              }
            },
          },
          {
            title: "检验手段",
            align: "center",
            dataIndex: "inspectMethod",
            customRender:(text)=>{
              if(!text){
                return "";
              }else{
                if(this.methodMap[text]){
                  return this.methodMap[text].title;
                }
                return  "";
              }
            }
            /*customRender: (text) => {
              if (!text) {
                return "";
              } else {
                return this.methodMap[text].title;
              }
            },*/
          },
          {
            title: "标准值",
            align: "center",
            dataIndex: "standardValue",
          },
          {
            title: "单位",
            align: "center",
            dataIndex: "standardUnit",
            customRender: (text) => {
              return this.standardUnitMap[text]?this.standardUnitMap[text].title:'';

            },
          },
          {
            title: "上限值",
            align: "center",
            dataIndex: "upperValue",
          },
          {
            title: "下限值",
            align: "center",
            dataIndex: "downValue",
          },
          {
            title: "参数",
            align: "center",
            dataIndex: "paramValue",
          },
          {
            title: "实测值",
            align: "center",
            dataIndex: "measuredValue",
          },
          {
            title: "单项判定",
            align: "center",
            dataIndex: "individualJudgment",
            customRender: (text) => {
              if (!text) {
                return "";
              } else {
                return  text==1?'PASS':'NG';
              }
            },
          },
          {
            title: "检验人",
            align: "center",
            dataIndex: "judge",
          },
        ],


        code: "",
        // 表头
        columns: [],
        //列设置
        settingColumns: [],
        dictOptions: {
          inspectStatus: [], //字典查询返回保存的数组
          inspectResult: [], //字典查询返回保存的数组
        },
        //列定义
        defColumns: [
          {
            title: "序号",
            dataIndex: "",
            key: "rowIndex",
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            },
          },
          {
            title: "送检单号",
            align: "center",
            dataIndex: "inspectBillno",
            scopedSlots: { customRender: "inspectBillno" } /*添加插槽*/,
          },
          {
            title: "车间",
            align: "center",
            dataIndex: "workroomname",
          },
          {
            title: "二级工序",
            align: "center",
            dataIndex: "processTwo",
          },
          {
            title: "线体",
            align: "center",
            dataIndex: "linename",
          },
          {
            title: "生产工单",
            align: "center",
            dataIndex: "productionBillno",
          },
          {
            title: "工序工单",
            align: "center",
            dataIndex: "processBillno",
          },
          {
            title: "设备编码",
            align: "center",
            dataIndex: "deviceCode",
          },
          {
            title: "产品编码",
            align: "center",
            dataIndex: "mcode",
          },
          {
            title: "产品名称",
            align: "center",
            dataIndex: "mname",
          },
          {
            title: "操作时间",
            align: "center",
            dataIndex: "updateTime",
          },

          {
            title: "检验次数",
            align: "center",
            dataIndex: "inspectTimes",
          },
          {
            title: "检验剩余时长(分钟)",
            align: "center",
            dataIndex: "remainingTime",
          },
          {
            title: "检验状态",
            align: "center",
            dataIndex: "inspectStatus",
            scopedSlots: { customRender: "inspectStatus" },
            // customRender: (text) => {
            //   if (!text) {
            //     return "";
            //   } else {
            //     var data = filterMultiDictText(
            //       this.dictOptions["inspectStatus"],
            //       text + ""
            //     );

            //     if (data == "检验完成") {
            //       return <div style="color:green">{data}</div>;
            //     } else {
            //       return <div style="color:red">{data}</div>;
            //     }
            //   }
            // },
          },
          {
            title: "检验结果",
            align: "center",
            dataIndex: "inspectResult",
            customRender: (text) => {
              if (!text) {
                return "";
              } else {
                var data = filterMultiDictText(
                        this.dictOptions["inspectResult"],
                        text + ""
                );
                if (data == "不合格") {
                  return <p-tag color="red"><p-icon type="close-circle" />{data}</p-tag>

                  //return <div style="color:red">{data}</div>;
                } else {
                  return <p-tag color="green"><p-icon type="check-circle" />{data}</p-tag>
                  //return <div style="color:green">{data}</div>;
                }
              }
            },
          },
          // {
          //   title: "操作",
          //   dataIndex: "action",
          //   align: "center",
          //   scopedSlots: { customRender: "action" },
          // },
        ],
        url: {
          list: "/mes-quality/mesQcInspectTask/list", //表格组件获得后台API的数据
          delete: "/mes-quality/mesQcInspectTask/delete",
          deleteBatch: "/mes-quality/mesQcInspectTask/deleteBatch",
          exportXlsUrl: "/mes-quality/mesQcInspectTask/exportXls",
          importExcelUrl: "/mes-quality/mesQcInspectTask/importExcel",
          getColumns: "/mes-quality/online/cgform/api/getColumns/",
          buttonAction: "/mes-quality/online/cgform/api/doButton",
        },

        /* 分页参数 */
        ipagination: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ["10", "20", "50"],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条";
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
        selectedMainId: "",
      };
    },
    computed: {
      importExcelUrl: function () {
        return `${api.test}${this.url.importExcelUrl}`;
      },
      getWidth: function () {
        if (this.defColumns.length > 14) {
          return { width: "500px" };
        }
      },
      newSelectedMainId: function () {
        if (typeof this.selectedMainId == "number") {
          return this.selectedMainId.toString();
        } else {
          return this.selectedMainId;
        }
      },
      tableScroll: function () {
        if (this.columns.length > 13) {
          return { x: this.columns.length * 150 - 450 };
        }
      },
      tableScroll3:function(){
        return {x:1500};
      },
    },

    created() {
      this.getMethodList();
      this.initStandardUnitList();
      this.mqListener();
      this.initButtonList();
      this.initColumns();
      this.setdefColumns();
    },

    methods: {

      mqListener(){
        if(this.mqLoad){
          this.loadData();
        }
      },


      drawerClose(){
        this.drawerVisible=false;
        this.activeKey=['1'];
      },

      data_dic(text, zi_duan) {
        /*插槽数据字典*/
        return filterMultiDictText(this.dictOptions[zi_duan], text + "");
      },
      // 1待检  跳转到“首件操作（操作员）
      // 2待线长确认  跳转到“首检确认操作”
      // 3待IPQC复核  跳转到“首检复核操作”
      // isPallet: 用来判断跳转普通操作页面还是线材/ 组件预制页面
      // inspectStatus: 用来判断跳转首检操作还是首检复核确认操作
//封装listToMap
      listToMap(list,name){
        let map = {};
        for(let i in list){
          map[list[i][name]] = list[i];
        }
        return map;
      },

      getMethodList(){
        getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'mes_inspect_method'}).then(res=>{
          if(res.success){
            this.methodList = res.data;
            this.methodMap = this.listToMap(this.methodList,'value');
          }
        })
      },

      currentLineChange(){

        let currentLine = this.currentLine;


        let param = {
          id:this.baseInfoData.id,
          wcCode:currentLine
        }
        postAction('/mes-quality/mesQcInspectTask/selectByLineNo',param).then(res=>{
          if(res.success){
            let data = res.data;
            this.checkProjectData2 = data;
          }else{
            this.$message.warning(res.msg)
          }
        })

      },

      initStandardUnitList(){
        getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'mes_details_tamplate_unit'}).then(res=>{
          if(res.success){
            this.standardUnitList = res.data;
            this.standardUnitMap = this.listToMap(this.standardUnitList,'value');
          }
        })
      },
      router_url(order_no_id, isPallet, inspectStatus) {

        /* 如果是1则是线缆预制和组件预制 跳线缆预制页面,其余跳操作员页面 */
        let mqData = this.mqData;
        if (isPallet == "1") {
          // 线材/组件预制页面
          switch (inspectStatus) {
            case 1:
              this.$emit('update:mqVisible', 3);
              this.$emit('update:mqLoad', this.mqLoad);
              mqData.id = order_no_id
              this.$emit('update:mqData', mqData);
              break;
            case 2:
              this.$emit('update:mqVisible', 4);
              this.$emit('update:mqLoad', this.mqLoad);
              mqData.id = order_no_id;
              mqData.isPallet = isPallet;
              mqData.inspectStatus = inspectStatus;
              this.$emit('update:mqData', mqData);

              break;
            case 3:
              this.$emit('update:mqVisible', 4);
              this.$emit('update:mqLoad', this.mqLoad);
              mqData.id = order_no_id;
              mqData.isPallet = isPallet;
              mqData.inspectStatus = inspectStatus;
              this.$emit('update:mqData', mqData);
              break;
            default:
              this.$emit('update:mqVisible', 4);
              this.$emit('update:mqLoad', this.mqLoad);
              mqData.id = order_no_id;
              mqData.isPallet = isPallet;
              mqData.inspectStatus = inspectStatus;
              this.$emit('update:mqData', mqData);
          }
        } else {
          // 非线缆普通操作页面

          switch (inspectStatus) {

            case 1:
              this.$emit('update:mqVisible', 2);
              this.$emit('update:mqLoad', this.mqLoad);
              mqData.id = order_no_id
              this.$emit('update:mqData', mqData);

              break;
            case 2:
              this.$emit('update:mqVisible', 4);
              this.$emit('update:mqLoad', this.mqLoad);
              mqData.id = order_no_id;
              mqData.isPallet = isPallet;
              mqData.inspectStatus = inspectStatus;

              break;
            case 3:
              this.$emit('update:mqVisible', 4);
              this.$emit('update:mqLoad', this.mqLoad);
              mqData.id = order_no_id;
              mqData.isPallet = isPallet;
              mqData.inspectStatus = inspectStatus;

              break;
            default:
              this.$emit('update:mqVisible', 4);
              this.$emit('update:mqLoad', this.mqLoad);
              mqData.id = order_no_id;
              mqData.isPallet = isPallet;
              mqData.inspectStatus = inspectStatus;

          }
        }
      },

      setdefColumns() {
        if (this.columns.length > 13) {
          let arrLength = this.columns.length - 1;
          this.columns.forEach((item, index) => {
            item["width"] = 130;
          });
          this.columns[arrLength]["fixed"] = "right";
          this.columns[arrLength - 1]["fixed"] = "right";
          this.columns[arrLength - 2]["fixed"] = "right";
          this.columns[0]["fixed"] = "left";
          this.columns[1]["fixed"] = "left";
        }
      },
      initColumns() {
        //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
        //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

        var key = this.$route.name + ":colsettings";
        let colSettings = Vue.ls.get(key);
        if (colSettings == null || colSettings == undefined) {
          let allSettingColumns = [];
          this.defColumns.forEach(function (item, i, array) {
            allSettingColumns.push(item.dataIndex);
          });
          this.settingColumns = allSettingColumns;
          this.columns = this.defColumns;
        } else {
          this.settingColumns = colSettings;
          const cols = this.defColumns.filter((item) => {
            if (item.key == "rowIndex" || item.dataIndex == "action") {
              return true;
            }
            if (colSettings.includes(item.dataIndex)) {
              return true;
            }
            return false;
          });
          this.columns = cols;
        }
      },
      //列设置更改事件
      onColSettingsChange(checkedValues) {
        var key = this.$route.name + ":colsettings";
        Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000);
        this.settingColumns = checkedValues;
        const cols = this.defColumns.filter((item) => {
          if (item.key == "rowIndex" || item.dataIndex == "action") {
            return true;
          }
          if (this.settingColumns.includes(item.dataIndex)) {
            return true;
          }
          return false;
        });
        this.columns = cols;
      },
      //高级查询方法
      handleSuperQuery(arg) {
        if (!arg) {
          this.superQueryParams = "";
          this.superQueryFlag = false;
        } else {
          this.superQueryFlag = true;
          this.superQueryParams = JSON.stringify(arg);
        }
        this.loadData();
      },
      // 获取查询条件
      getQueryParams() {
        let sqp = {};
        if (this.superQueryParams) {
          sqp["superQueryParams"] = encodeURI(this.superQueryParams);
        }
        var param = Object.assign(sqp, this.queryParam, this.isorter);
        param.field = this.getQueryField();
        param.pageNo = this.ipagination.current;
        param.limit = this.ipagination.pageSize;
        return filterObj(param);
      },
      initDictConfig() {
        // 用状态的值发送请求查询数据字典里的状态值对应的字符串
        initDictOptions("mes_inspect_status").then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, "inspectStatus", res.data);
          }
        });
        // 用检验结果的值发送请求查询数据字典里的检验结果的值对应的字符串
        initDictOptions("mes_is_qualified").then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, "inspectResult", res.data);
          }
        });
      },
      clickThenSelect(record) {
        return {
          on: {
            click: () => {
              this.rowId = record.id;
              this.onSelectChange(record.id.toString().split(","), [record]);
            },
            dblclick: () => {
              let id = record.id;
              getAction('/mes-quality/mesQcInspectTask/selectById?id='+id).then(res=>{
                if(res.success){
                  if(res.data){
                    this.drawerVisible = true;
                    this.baseInfoData = res.data;

                    let data = res.data;
                    let isPallet = data.isPallet;
                    let inspectStatus  = data.inspectStatus;
                    if(isPallet==1){
                      if(inspectStatus==2){
                        this.pageState = 3;
                      }else{
                        this.pageState = 4;
                      }
                    }else{
                      if(inspectStatus==2){
                        this.pageState = 1;
                      }else{
                        this.pageState = 2;
                      }
                    }

                    if(isPallet==1) {

                      this.selectLineList = data.qualifiedPallet;

                    }

                  }
                }else{
                  this.$message.warning(res.msg);
                }
              })
            }
          },
        };
      },
      setRowClassName(record){
        if(record.id===this.rowId){
          if(record.remainingTime<=0){
            if(record.inspectStatus==4){
              return 'clickRowStyl';
            }else{
              return 'clickRowStyl3';
            }

          }else{
            return 'clickRowStyl';
          }
        }else{
          if(record.remainingTime<=0&&record.inspectStatus!=4){
            return 'clickRowStyl2';
          }
        }

      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
        this.selectedMainId = "";
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedMainId = selectedRowKeys[0];
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
      },
      loadData(arg) {
        if (!this.url.list) {
          this.$message.error("请设置url.list属性!");
          return;
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        this.onClearSelected();
        var params = this.getQueryParams(); //查询条件
        this.loading = true;

        getAction(this.url.list, params).then((res) => {
          //表格组件获得后台API的数据
          if (res.success) {
            this.dataSource = res.data.records;
            this.ipagination.total = res.data.total;

          }
          if (res.code === 510) {
            this.$message.warning(res.msg);
          }

        }).then(res=>{
          this.loading = false;
        });
      },

      // 弹出窗组件
      showDemoModal() {
        this.$refs.modalCompon.modalShow();
      },
      // 点击btn获取数据
      btnGetData(tableName, title) {
        getAction(`${this.url.getColumns}`, {
          tableName: tableName,
        }).then((res) => {
          if (res.code == 0) {
            this.queryInfo = res.data.columns;
            this.title = title;
            this.dictOptions = res.data.dictOptions;
            this.showDemoModal();
          } else {
            this.$message.warning(res.msg);
          }
        });
      },

      //筛选分组
      getGroupTag(arrList) {
        let arr = [];
        var map = {},
                dest = [];
        arrList.forEach((item, index) => {
          if (item.groupTag) {
            arr.push(item);
          }
        });
        for (var i = 0; i < arr.length; i++) {
          var ai = arr[i];
          if (!map[ai.groupTag]) {
            dest.push({
              groupTag: ai.groupTag,
              name: ai.groupName,
              data: [ai],
            });
            map[ai.groupTag] = ai;
          } else {
            for (var j = 0; j < dest.length; j++) {
              var dj = dest[j];
              if (dj.groupTag == ai.groupTag) {
                dj.data.push(ai);
                break;
              }
            }
          }
        }
        this.groupTag = dest;

      },
      showLinkButton(item, record) {
        let btn = new ButtonExpHandler(item.exp, record);
        return btn.show;
      },
      initButtonList() {
        getAction(`${this.url.getColumns}8ac49ec7733bce48017350266d7a00f5`).then(
                (res) => {
                  console.log("--获取自定义按钮->>", res);
                  if (res.success) {
                    this.code = res.data.code;
                    this.initCgButtonList(res.data.cgButtonList);
                    this.initCgEnhanceJs(res.data.enhanceJs);
                    this.getGroupTag(res.data.cgButtonList);
                  } else {
                    this.$message.warning(res.msg);
                  }
                }
        );
      },
      initCgEnhanceJs(enhanceJs) {
        //console.log("--onlineList-js增强",enhanceJs)
        if (enhanceJs) {
          let Obj = eval("(" + enhanceJs + ")");
          this.EnhanceJS = new Obj(getAction, postAction, deleteAction);
          this.cgButtonJsHandler("created");
        } else {
          this.EnhanceJS = "";
        }
      },
      initCgButtonList(btnList) {
        let linkArr = [];
        let buttonArr = [];
        if (btnList && btnList.length > 0) {
          for (let i = 0; i < btnList.length; i++) {
            let temp = btnList[i];
            if (temp.buttonStyle == "button") {
              buttonArr.push(temp);
            } else if (temp.buttonStyle == "link") {
              linkArr.push(temp);
            }
          }
        }
        this.cgButtonLinkList = [...linkArr];
        this.cgButtonList = [...buttonArr];
        console.log("链接增强", this.cgButtonLinkList);
      },
      cgButtonJsHandler(buttonCode) {
        if (this.EnhanceJS[buttonCode]) {
          this.EnhanceJS[buttonCode](this);
        }
      },
      cgButtonActionHandler(buttonCode) {
        //处理自定义button的 需要配置该button自定义sql
        if (!this.selectedRowKeys || this.selectedRowKeys.length == 0) {
          this.$message.warning("请先选中一条记录");
          return false;
        }
        if (this.selectedRowKeys.length > 1) {
          this.$message.warning("请只选中一条记录");
          return false;
        }
        let params = {
          formId: this.code,
          buttonCode: buttonCode,
          dataId: this.selectedRowKeys[0],
        };
        console.log("自定义按钮请求后台参数：", params);
        postAction(this.url.buttonAction, params).then((res) => {
          if (res.success) {
            this.loadData();
            this.$message.success("处理完成!");
          } else {
            this.$message.warning("处理失败!");
          }
        });
      },
      cgButtonLinkHandler(record, buttonCode, optType) {
        if (optType == "js") {
          if (this.EnhanceJS[buttonCode]) {
            this.EnhanceJS[buttonCode](this, record);
          }
        } else if (optType == "action") {
          let params = {
            formId: this.code,
            buttonCode: buttonCode,
            dataId: record.id,
          };
          console.log("自定义按钮link请求后台参数：", params);
          postAction(this.url.buttonAction, params).then((res) => {
            if (res.success) {
              this.loadData();
              this.$message.success("处理完成!");
            } else {
              this.$message.warning("处理失败!");
            }
          });
        }
      },
    },
    mounted() {

    },
  };
</script>
<style scoped>
  @import "~@assets/less/common.less";
  /deep/.clickRowStyl td{
    background:#00b4ed !important;
  }
  /deep/.clickRowStyl2 td{
    color:red;
  }

  /deep/.clickRowStyl3 td{
    background:#00b4ed !important;
    color:red;
  }

  /deep/.ant-table-tbody.clickRowStyl:hover>td {
    background-color:#00b4ed
  }
</style>
